package com.nuanshui.framework.res;

import com.nuanshui.framework.lang.SysStringUtils;
import com.nuanshui.framework.utils.HttpUtil;
import com.nuanshui.heatedloan.enums.FileBelong;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by zxh on 2017/7/2.
 */
public class UploadRequest {


    public UploadRequest()
    {
        belong=FileBelong.PRODUCT;
        requestFlag=0;
        responseFlag=1;
    }

    private MultipartFile multipartFile;

    private String fetchUrl;

    private InputStream inputStream;

    private FileBelong belong;

    private Integer requestFlag;

    private Integer responseFlag;

    public void setMultipartFile(MultipartFile multipartFile) {
        this.multipartFile=multipartFile;
    }

    public InputStream getInputStream() {

        if(inputStream==null)
        {
            if(multipartFile!=null)
            {
                try {
                    inputStream=multipartFile.getInputStream();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(SysStringUtils.isNotEmpty(fetchUrl))
            {
                inputStream= HttpUtil.getInputStream(fetchUrl);
            }
        }

        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public FileBelong getBelong() {
        return belong;
    }

    public void setBelong(FileBelong belong) {
        this.belong = belong;
    }

    public Integer getRequestFlag() {
        return requestFlag;
    }

    public void setRequestFlag(Integer flag) {
        this.requestFlag = flag;
    }

    public String getFetchUrl() {
        return fetchUrl;
    }

    public void setFetchUrl(String fetchUrl) {
        this.fetchUrl = fetchUrl;
    }

    public Integer getResponseFlag() {
        return responseFlag;
    }

    public void setResponseFlag(Integer responseFlag) {
        this.responseFlag = responseFlag;
    }
}
